package com.budwk.app.sqfwV2.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.alibaba.fastjson.JSONObject;
import com.budwk.app.sqfw.dto.building.BuildQueryReqVo;
import com.budwk.app.sqfw.dto.building.BuildingInfoDTO;
import com.budwk.app.sqfw.models.BuildingInfo;
import com.budwk.app.sqfw.services.BuildingInfoService;
import com.budwk.starter.common.openapi.annotation.ApiDefinition;
import com.budwk.starter.common.openapi.annotation.ApiFormParams;
import com.budwk.starter.common.openapi.annotation.ApiOperation;
import com.budwk.starter.common.result.Result;
import com.budwk.starter.log.annotation.SLog;
import lombok.extern.slf4j.Slf4j;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.*;

@IocBean
@At("/platform/sqfwV2/buildingInfo")
@ApiDefinition(tag = "楼栋信息api")
@Slf4j
public class BuildingInfoController {

    @Inject
    private BuildingInfoService buildingInfoService;

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "新增楼栋信息接口")
    @ApiFormParams(implementation = BuildingInfoDTO.class)
    @SLog(tag = "新增楼栋信息接口", value = "${args[0]}")
    @SaCheckLogin
    public Result<BuildingInfoDTO> submitData(@Param("..") BuildingInfoDTO dto) {
        log.info("buildingInfo submitData param: {}", JSONObject.toJSONString(dto));
        return Result.data(buildingInfoService.submitData(dto));
    }

    @At
    @Ok("json")
    @GET
    @ApiOperation(name = "查询楼栋详情信息")
    @SaCheckLogin
    public Result<BuildingInfo> getBuildDetail(@Param("buildingId") String buildingId) {
        return Result.data(buildingInfoService.fetch(buildingId));
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "分页查询楼栋信息")
    @ApiFormParams(implementation = BuildQueryReqVo.class)
    @SaCheckLogin
    public Result<?> listByPage(@Param("..") BuildQueryReqVo dto) {
        log.info("buildingInfo listByPage param: {}", JSONObject.toJSONString(dto));
        return buildingInfoService.listByPage(dto);
    }

    @At
    @Ok("json")
    @DELETE
    @ApiOperation(name = "删除楼栋")
    @ApiFormParams(implementation = BuildingInfo.class)
    @SLog(tag = "删除楼栋", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> deleteBuilding(@Param("..") BuildingInfo info) {
        log.info("buildingInfo deleteBuilding param: {}", JSONObject.toJSONString(info));
        buildingInfoService.deleteBuilding(info);
        return Result.success();
    }

    @At
    @Ok("json")
    @GET
    @ApiOperation(name = "房屋楼栋建立关系")
    @SaCheckLogin
    public Result<?> buildHouseRelate() {
        buildingInfoService.buildHouseRelate();
        return Result.success();
    }

}
